/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.ImplementInterface;

import Interface.IRemoteCustomer;
import Server.DTO.Customer_DTO;
import java.rmi.RemoteException;
import static java.rmi.server.RemoteServer.getClientHost;
import java.rmi.server.ServerNotActiveException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author 10520_000
 */
public class CustomerObject extends UnicastRemoteObject implements IRemoteCustomer {

    public CustomerObject() throws RemoteException {
        super();
    }

    @Override
    public int Insert(Customer_DTO info) throws RemoteException {
        try {
            System.out.println("Invoke Insert from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return CustomerRepository.Insert(info);
    }

    @Override
    public int Update(Customer_DTO info) throws RemoteException {
        try {
            System.out.println("Invoke Update from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return CustomerRepository.Update(info);
    }

    @Override
    public int Delete(Customer_DTO info) throws RemoteException {
        try {
            System.out.println("Invoke Delete from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return CustomerRepository.Delete(info);
    }

    @Override
    public void DeleteAll() throws RemoteException {
        try {
            System.out.println("Invoke DeleteALl from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        CustomerRepository.DeleteAll();
    }

    @Override
    public ArrayList FindAll() throws RemoteException {
        try {
            System.out.println("Invoke FindAll from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return CustomerRepository.FindAll();
    }

    @Override
    public Customer_DTO FindByCustomerID(String str_CustomerID) throws RemoteException {
        try {
            System.out.println("Invoke FindByName from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return CustomerRepository.FindByCustomerID(str_CustomerID);
    }

//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    @Override
    public String GetCustomerID(String str_fullname, String str_cmnd) throws RemoteException {
        String result = "";
        try {
            result = CustomerRepository.GetCustomerID(str_fullname, str_cmnd);
        } catch (SQLException ex) {
            Logger.getLogger(CustomerObject.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }

    @Override
    public ArrayList GetCustomers(Customer_DTO info) throws RemoteException {
        ArrayList arr = null;
        try {
            arr = CustomerRepository.GetCustomers(info);
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        } catch (SQLException ex) {
            Logger.getLogger(CustomerObject.class.getName()).log(Level.SEVERE, null, ex);
        }
        return arr;
    }
    public static void main(String[] str) throws RemoteException
    {
        CustomerObject obj = new CustomerObject();
        Customer_DTO info = new Customer_DTO();
        info.setFullName("NGOC SAM");
        info.setIDNumber("215250401");
        ArrayList arr = obj.GetCustomers(info);
        for(int i=0;i<arr.size();i++)
        {
            System.out.println(((Customer_DTO)arr.get(i)).getCustomerID());
        }
    }
}
